package com.test.delay.controller;


import com.test.delay.config.RabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

@RestController
@RequestMapping(value = "/test")
public class testDelayController {
    private static final Logger log = LoggerFactory.getLogger(testDelayController.class);
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping
    public void delay(){
        String delay="这是一条消息";
        rabbitTemplate.convertAndSend(RabbitConfig.REGISTER_DELAY_EXCHANGE,RabbitConfig.DELAY_ROUTING_KEY,delay,message->{
            message.getMessageProperties().setExpiration(5*1000+"");
            return message;
        });
        log.info("[发送时间] - [{}]", LocalDateTime.now());
    }
}
